<template>
  <div p-5>
    <DynamicTable
      bordered
      :data-request="loadData"
      :columns="columns"
      row-key="id"
      @resize-column="handleResizeColumn"
      :scroll="{
        y: 'calc(100vh - 330px)',
      }"
    >
    </DynamicTable>
  </div>
</template>
<script setup lang="ts">
  import { columns } from './columns';
  import { getTableListApi } from '@/api/system/dayLog';
  import { useTable, type OnChangeCallbackParams } from '@/components/core/dynamic-table';
  const [DynamicTable] = useTable();

  const loadData = async (
    params,
    onChangeParams: OnChangeCallbackParams,
  ): Promise<API.TableListResult> => {
    if (params?.time?.length) {
      params.startTime = params.time[0];
      params.endTime = params.time[1];
    }
    const data = await getTableListApi(params);
    return new Promise((resolve) => {
      setTimeout(() => {
        resolve({
          list: data,
          ...params,
        });
      }, 500);
    });
  };

  const handleResizeColumn = (w, col) => {
    col.width = w;
  };
</script>
<style scoped lang="less"></style>
